package edu.pe.cayetano.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import org.apache.commons.beanutils.RowSetDynaClass;

import ws.synopsis.frmwrk.common.BResult;
import edu.pe.cayetano.framework.DAOException;
import edu.pe.cayetano.seccd.constantes.ConstantesSECCD;

public class CurriculaDAO extends BaseDAO{

	public CurriculaDAO(Connection cnx) {
		super(cnx);
	}
	
	/**
	 * Metodo que retorna el listado de ciclos
	 * */
	public BResult listarCurriculaxNivelAcademico(String nivel_id) throws Exception{

		PreparedStatement   	pstmt 		 		= null;
		ResultSet 				rs 			 		= null;
		BResult					ret					= new BResult();
		RowSetDynaClass 		rsdc				= null;
		try{
				StringBuffer query  = new StringBuffer();
				query.append(" SELECT CURRICULA_ID AS CODIGO,A.NOMBRE AS NOMBRE_CURR,A.NIVEL_ID AS COD_NIVEL,B.NOMBRE AS NOMBRE_NIVEL");
				query.append(" FROM "+schema+"CURRICULA A INNER JOIN "+schema+"NIVEL_ACADEMICO B");
				query.append(" ON B.NIVEL_ID=A.NIVEL_ID");
				query.append(" WHERE A.NIVEL_ID="+nivel_id); 
				System.out.println("[SECCD][CurriculaDAO][listarCurriculaxNivelAcademico]:query:"+query.toString());
				pstmt = getConnection().prepareStatement(query.toString());
				rs=pstmt.executeQuery();
				rsdc = new RowSetDynaClass(rs, false);
				ret.setObject(rsdc);
				ret.setCode(ConstantesSECCD.EXITO_RET);
			}catch(Exception e){
				ret.setObject(null);
				ret.setCode(ConstantesSECCD.ERROR_RET);
				throw new DAOException(e.getMessage());
			}finally{
				try{
					pstmt.close();
					rs.close();
				}catch(Exception e){
						
				}
			}
		return ret;
	}

}
